package com.example.sw.myappmoban.ui.dashboard;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import com.example.sw.myappmoban.R;

public class DashboardFragment extends Fragment {

    private TextView txt1;
    private Button btn1;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {


        View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
        //alt 回车 碎片framengten找到父布局 ？
        initView(root);
        setListener();

        return root;
    }



    private void setListener() {
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                txt1.setText("你点击了按钮");
                SharedPreferences sp=getActivity().
                        getSharedPreferences("userinfo", Context.MODE_PRIVATE);
                int uid =sp.getInt("uid",0);
                String usn =sp.getString("usn","");

                txt1.setText("欢迎你，"+uid+"号用户："+usn);


            }
        });
    }

    private void initView(View root) {
        txt1 =root.findViewById(R.id.txt1);
        btn1 =root.findViewById(R.id.btn1);
    }
}